import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import user from './user'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 100,
    proList: []
  },
  getters: {
    proLen (state) {
      return state.proList.length
    }
  },
  mutations: { // 唯一改变状态的方式就是显示的提交mutation
    updateCount (state, data) { // 第一个参数就是state，第二参数就是需要传递过来的值
      state.count = data
    },
    updateProList (state, data) {
      state.proList = data
    }
  },
  actions: {
    getProListData (context) {
      console.log(context) // commit state
      axios.get('http://121.89.205.189/api/pro/list').then(res => {
        context.commit('updateProList', res.data.data)
      })
    }
  },
  modules: {
    user
  }
})
